﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;

namespace DataAccess
{
    public class MenuRepository : ConnectionClass
    {
        public MenuRepository() : base() { }

        public IEnumerable<Menu> getMenus(int roleId)
        {
            return new UserRepository().GetRole(roleId).Menus.AsEnumerable();
        }
        
        public IEnumerable<Menu> getMenus(string username)
        {
            return (
                        from u in db.Users
                        from r in u.Roles
                        from m in r.Menus
                        where u.UserName == username
                        orderby m.Position
                        select m
                ).Distinct().AsEnumerable();

        }
    }
}
